home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_pas / ddplus63.zip / JUNGLE.PAS < prev    next >
Pascal/Delphi Source File  |  1994-07-17  |  12KB  |  487 lines

  1. uses ddplus,crt;
  2.  
  3. { EXAMPLE DOOR: The Jungle!                                               }
  4. {               By Scott Baker                                            }
  5. {                                                                         }
  6. {      One of my friends wanted me to whip this thing up, but I never     }
  7. { finished it. So here it is! Basically, this door operates as a type     }
  8. { of "Never Ending Story". Users continually add on to the end of a       }
  9. { large "tablet"  which contains all of the dialog.                       }
  10. {      The program is not quite finished - there are some maintenance     }
  11. { options that are really necessary (such as purging the table of old     }
  12. { data), but there isn't much work left.                                  }
  13. {      Also, if you do use any of this code in your own program, I        }
  14. { that you credit my name.                                                }
  15.  
  16. {$V-}
  17.  
  18. const
  19.  numusers=100;
  20. type
  21.  setuprec=record
  22.            numstr: word;
  23.            minwords,
  24.            maxwords,
  25.            minpunct,
  26.            maxpunct,
  27.            mincaps,
  28.            maxcaps,
  29.            minpro,
  30.            maxpro: word;
  31.            minpass: word;
  32.           end;
  33.  
  34.  userrec=record
  35.           realname: string[35];
  36.           alias: string[35];
  37.           scrsize: word;
  38.  
  39.           totalcaps: longint;
  40.           totalpunct: longint;
  41.           totalpro: longint;
  42.           totalwords: longint;
  43.           totallines: longint;
  44.           totalposts: longint;
  45.          end;
  46.  
  47. const
  48.  setup: setuprec= (numstr: 5000;
  49.                    minwords: 3;
  50.                    maxwords: 10;
  51.                    minpunct: 1;
  52.                    maxpunct: 10;
  53.                    mincaps: 2;
  54.                    maxcaps: 20;
  55.                    minpro: 0;
  56.                    maxpro: 3;
  57.                    minpass: 3);
  58.  
  59. type
  60.  sttypetype=(Authorident,thetext);
  61.  strrec=record
  62.          sttype: sttypetype;
  63.          numlines: word;
  64.          str: string[80];
  65.         end;
  66. var
  67.  strfile: file of strrec;                 {File to hold the tablet          }
  68.  header: strrec;                          {"header" for the tablet          }
  69.  
  70.  numuserlines: word;                      {Number of lines user has typed in}
  71.  userlines: array[1..500] of string[80];  {Holds users typing for session   }
  72.  
  73.  user: userrec;                           {Current user record              }
  74.  userfile: file of userrec;               {File to hold user records        }
  75.  usernum: word;                           {Record number of user            }
  76.  
  77.  exitsave: pointer;                       {for exit procedure               }
  78.  
  79. procedure AddStr(s: string);
  80. var
  81.  st:strrec;
  82. begin;
  83.  inc(header.numlines);
  84.  st.sttype:=thetext;
  85.  st.str:=s;
  86.  seek(strfile,header.numlines);
  87.  write(strfile,st);
  88. end;
  89.  
  90. procedure openfiles;
  91. var
  92.  s: strrec;
  93.  a: integer;
  94. begin;
  95.  assign(strfile,'TEXT.DAT');
  96.  {$I-}
  97.  reset(strfile);
  98.  {$I+}
  99.  if ioresult<>0 then begin;
  100.   rewrite(strfile);
  101.   header.sttype:=authorident;
  102.   header.str:='';
  103.   header.numlines:=1;
  104.   s.sttype:=authorident;
  105.   s.str:='Introduction';
  106.   for a:=1 to setup.numstr do write(strfile,s);
  107.   reset(strfile);
  108.  
  109.   Addstr('Welcome to ... The Jungle!');
  110.   Addstr('(c) 1991 Scott Baker & Michael Crosson.');
  111.   addstr('');
  112.   addstr('The world''s best free-format message system! Where it doesn''t matter how');
  113.   addstr('you post, where you post, just that you post! ');
  114.  
  115.   seek(strfile,0);
  116.   write(strfile,header);
  117.  end;
  118.  reset(strfile);
  119.  read(strfile,header);
  120.  
  121.  assign(userfile,'JNGLUSER.DAT');
  122.  {$I-}
  123.  reset(userfile);
  124.  {$I+}
  125.  if ioresult<>0 then begin;
  126.   rewrite(userfile);
  127.   fillchar(user,sizeof(user),0);
  128.   for a:=1 to numusers+1 do write(userfile,user);
  129.  end;
  130.  reset(userfile);
  131. end;
  132.  
  133. {$F+}
  134. procedure myexit;
  135. begin;
  136.  if usernum<>0 then begin;
  137.   seek(userfile,usernum);
  138.   write(userfile,user);
  139.  end;
  140.  close(userfile);
  141.  close(strfile);
  142.  exitproc:=exitsave;
  143. end;
  144. {$F-}
  145.  
  146. procedure login;
  147. var
  148.  a,b,c: integer;
  149.  u: userrec;
  150.  s: string;
  151. begin;
  152.  swriteln('Welcome to The Jungle!');
  153.  swriteln('');
  154.  swriteln('Standby, finding your place in the jungle!');
  155.  b:=0;
  156.  c:=0;
  157.  for a:=1 to numusers do begin;
  158.   seek(userfile,a);
  159.   read(userfile,u);
  160.   if u.realname=stu(user_first_name+' '+user_last_name) then b:=a;
  161.   if (u.realname='') and (c=0) then c:=a;
  162.  end;
  163.  swriteln('');
  164.  if (b=0) and (c=0) then begin;
  165.   swriteln('Sorry, the jungle is kind of crowded right now. Maybe some other time!');
  166.   halt;
  167.  end;
  168.  usernum:=b;
  169.  if (b=0) then begin;
  170.   usernum:=c;
  171.   fillchar(user,sizeof(user),0);
  172.   user.realname:=stu(user_first_name+' '+user_last_name);
  173.   swriteln('Looks like this is your first visit to the jungle! First, let me ask you');
  174.   swriteln('a few questions....');
  175.   swriteln('');
  176.   repeat;
  177.    swrite('What would you like as an alias? ');
  178.    sread(user.alias);
  179.    swrite(namestr(user.alias)+', Correct (Y/N) ? ');
  180.    sread_char(ch);
  181.    ch:=upcase(ch);
  182.   until ch='Y';
  183.   swriteln('');
  184.   repeat;
  185.    swrite('How many screen lines do you have (15-50) ? ');
  186.    sread(s);
  187.    val(s,user.scrsize,a);
  188.    swrite(wva(user.scrsize)+', Right (Y/N) ? ');
  189.    sread_char(ch);
  190.    ch:=upcase(ch);
  191.   until ch='Y';
  192.   swriteln('');
  193.  end;
  194. end;
  195.  
  196. procedure ListFrom(n: word);
  197. var
  198.  a: integer;
  199.  s: strrec;
  200.  s2,s3: string;
  201. begin;
  202.  if n>header.numlines then n:=header.numlines;
  203.  for a:=n to header.numlines do begin;
  204.   seek(strfile,a);
  205.   read(strfile,s);
  206.   if s.sttype=authorident then begin;
  207.    swriteln('');
  208.    set_Foreground(lightgray);
  209.    set_background(1);
  210.    s3:='|||||||||||||||||||||||';
  211.    s2:=' Line: '+wva(a)+' ';
  212.    move(s2[1],s3[8],length(s2));
  213.    swrite(s3);
  214.    set_background(0);
  215.    swriteln('');
  216.    swriteln('');
  217.   end else begin;
  218.    set_foreground(lightgray);
  219.    swriteln(s.str);
  220.   end;
  221.  end;
  222. end;
  223.  
  224. procedure adduser(s: string);
  225. begin;
  226.  inc(numuserlines);
  227.  userlines[numuserlines]:=s;
  228. end;
  229.  
  230. procedure listuser;
  231. var
  232.  a: integer;
  233. begin;
  234.  set_foreground(lightred);
  235.  swriteln('Your Text:');
  236.  set_foreground(white);
  237.  for a:=1 to numuserlines do swriteln(userlines[a]);
  238. end;
  239.  
  240. procedure DispBar(s: string; min,max,v: word; var pass: word);
  241. var
  242.  a: integer;
  243.  s2: string;
  244. begin;
  245.  set_foreground(cyan);
  246.  swrite(s);
  247.  set_foreground(white);
  248.  str(v:3,s2);
  249.  swrite(s2+'  ');
  250.  for a:=0 to 30 do begin;
  251.   if a<=v then set_background(cyan) else set_background(blue);
  252.   if a=min then begin;
  253.    set_foreground(lightred);
  254.    swrite('|');
  255.   end else if a=max then begin;
  256.    set_foreground(lightred);
  257.    swrite('|');
  258.   end else swrite(' ');
  259.  end;
  260.  set_foreground(7);
  261.  set_background(0);
  262.  swrite('  ');
  263.  if (v>=min) and (v<=max) then begin;
  264.   set_Foreground(0);
  265.   set_background(green);
  266.   swrite('[PASS]');
  267.   inc(pass);
  268.  end else begin;
  269.   set_foreground(0);
  270.   set_background(red);
  271.   swrite('[FAIL]');
  272.  end;
  273.  set_foreground(7);
  274.  set_background(0);
  275.  swriteln('');
  276. end;
  277.  
  278. procedure DoBars(lines,words,punct,caps,pro: longint; var pass: word);
  279. begin;
  280.  pass:=0;
  281.  DispBar('Words Per Line          : ',setup.minwords,setup.maxwords,words div lines,pass);
  282.  swriteln('');
  283.  DispBar('Punctuation Per Line    : ',setup.minpunct,setup.maxpunct,punct div lines,pass);
  284.  swriteln('');
  285.  dispbar('Capitol Letters Per Line: ',setup.mincaps,setup.maxcaps,caps div lines,pass);
  286.  swriteln('');
  287.  dispbar('Profanity               : ',setup.minpro,setup.maxpro,pro div lines,pass);
  288. end;
  289.  
  290. procedure checkusertext;
  291. const
  292.  pchars= [':'..'@','['..'`','!'..'/'];
  293. var
  294.  caps: word;
  295.  words: word;
  296.  punct: word;
  297.  pro: word;
  298.  found: boolean;
  299.  a,b: integer;
  300.  lastspace: boolean;
  301.  pros: array[1..255] of string[30];
  302.  numpros: word;
  303.  s2: string;
  304.  f: text;
  305.  pass: word;
  306. begin;
  307.  if numuserlines=0 then exit;
  308.  sclrscr;
  309.  set_foreground(lightgray);
  310.  swriteln('Standby, Testing your text for content:');
  311.  swriteln('');
  312.  if exist('JUNGBAD.TXT') then begin;
  313.   assign(f,'JUNGBAD.TXT');
  314.   reset(f);
  315.   numpros:=0;
  316.   while not eof(F) do begin;
  317.    inc(numpros);
  318.    readln(f,pros[numpros]);
  319.    if length(pros[numpros])<2 then dec(numpros);
  320.   end;
  321.   close(F);
  322.  end else numpros:=0;
  323.  caps:=0;
  324.  words:=0;
  325.  punct:=0;
  326.  pro:=0;
  327.  for a:=1 to numuserlines do begin;
  328.   inc(words);
  329.   lastspace:=true;
  330.   swrite(#13+'Line: '+wva(a));
  331.   delay(125);
  332.   for b:=1 to length(userlines[a]) do begin;
  333.    if userlines[a][b] in pchars then inc(punct);
  334.    if userlines[a][b] in ['A'..'Z'] then inc(caps);
  335.    if (userlines[a][b] in pchars) or (userlines[a][b] = ' ') then begin;
  336.     if not lastspace then inc(words);
  337.     lastspace:=true;
  338.    end else lastspace:=false;
  339.   end;
  340.   s2:=userlines[a];
  341.   repeat;
  342.    found:=false;
  343.    for b:=1 to numpros do if pos(stu(pros[b]),stu(s2))<>0 then begin;
  344.     found:=true;
  345.     inc(pro);
  346.     delete(s2,pos(stu(pros[b]),stu(s2)),length(pros[b]));
  347.    end;
  348.   until found=false;
  349.  end;
  350.  while wherex>1 do swrite(#8' '#8);
  351.  set_foreground(7);
  352.  set_background(1);
  353.  swrite('[-- User text analysis --]');
  354.  set_foreground(7);
  355.  set_Background(0);
  356.  swriteln('');
  357.  swriteln('');
  358.  dobars(numuserlines,words,punct,caps,pro,pass);
  359.  swriteln('');
  360.  if pass<setup.minpass then begin;
  361.   set_Foreground(lightred);
  362.   swriteln('You did not pass enough tests! Your writing has been discarded!');
  363.   numuserlines:=0;
  364.  end else begin;
  365.   set_Foreground(lightgreen);
  366.   swriteln('You passed! Your writing is saved.');
  367.   user.totalwords:=user.totalwords+words;
  368.   user.totalpunct:=user.totalpunct+punct;
  369.   user.totalcaps:=user.totalcaps+caps;
  370.   user.totalpro:=user.totalpro+pro;
  371.   user.totallines:=user.totallines+numuserlines;
  372.  end;
  373. end;
  374.  
  375. procedure ShowHistory;
  376. var
  377.  pass: word;
  378. begin;
  379.  swriteln('');
  380.  swriteln('Your posting history:');
  381.  swriteln('');
  382.  if user.totallines=0 then begin;
  383.   swriteln('You have no posting history!');
  384.   exit;
  385.  end;
  386.  dobars(user.totallines,user.totalwords,user.totalpunct,user.totalcaps,user.totalpro,pass);
  387. end;
  388.  
  389. procedure wreadln(var thestr,wwrap: string);
  390. var
  391.  s,s2: string[162];
  392.  a,b,c: integer;
  393.  ch: char;
  394.  done: boolean;
  395. begin;
  396.  done:=false;
  397.  if thestr<>'' then swrite(thestr);
  398.  wwrap:='';
  399.  repeat;
  400.   sread_char(ch);
  401.   if (ch=#8) and (length(thestr)>0) then begin;
  402.    swrite(#8+' '+#8);
  403.    delete(thestr,length(thestr),1);
  404.   end;
  405.   if not (ch in [#$0d,#$08]) then begin;
  406.    thestr:=thestr+ch;
  407.    swrite(ch);
  408.   end;
  409.   if length(thestr)>72 then begin;
  410.    c:=0;
  411.    for b:=1 to length(thestr) do if thestr[b]=' ' then c:=b;
  412.    s:='';
  413.    if c>60 then begin;
  414.     for b:=c+1 to length(thestr) do begin;
  415.      s:=s+thestr[b];
  416.      swrite(#8+' '+#8);
  417.     end;
  418.     for b:=c to length(thestr) do delete(thestr,length(thestr),1);
  419.    end;
  420.    wwrap:=s;
  421.    done:=true;
  422.   end;
  423.  until (ch=#13) or (done);
  424.  swriteln('');
  425. end;
  426.  
  427. procedure mainloop;
  428. var
  429.  s: string;
  430.  a,b: integer;
  431.  done: boolean;
  432.  wwrap: string;
  433. begin;
  434.  done:=false;
  435.  wwrap:='';
  436.  repeat;
  437.   set_foreground(lightcyan);
  438.   swrite('> ');
  439.   set_foreground(white);
  440.   s:=wwrap;
  441.   wreadln(s,wwrap);
  442.   set_foreground(lightgray);
  443.   if stu(s)='H' then showhistory;
  444.   val(s,a,b);
  445.   if a<>0 then begin;
  446.    listfrom(a);
  447.    swriteln('');
  448.    listuser;
  449.    swriteln('');
  450.   end else if (stu(s)='Q') or (stu(s)='O') or (stu(s)='QUIT') or (stu(s)='EXIT') then begin;
  451.    done:=true;
  452.   end else if stu(s)<>'H' then adduser(s);
  453.  until done;
  454.  checkusertext;
  455. end;
  456.  
  457. procedure savefiles;
  458. var
  459.  a: integer;
  460.  s: strrec;
  461. begin;
  462.  if numuserlines<>0 then begin;
  463.   s.sttype:=authorident;
  464.   s.str:=stu(user_first_name+' '+user_last_name);
  465.   inc(header.numlines);
  466.   seek(strfile,header.numlines);
  467.   write(strfile,s);
  468.  end;
  469.  for a:=1 to numuserlines do addstr(userlines[a]);
  470.  seek(strfile,0);
  471.  write(strfile,header);
  472. end;
  473.  
  474. begin;
  475.  initdoordriver('DOORDRIV.CTL');
  476.  morechk:=false;
  477.  progname:='The Jungle!';
  478.  numuserlines:=0;
  479.  usernum:=0;
  480.  openfiles;
  481.  exitsave:=exitproc;
  482.  exitproc:=@myexit;
  483.  login;
  484.  mainloop;
  485.  savefiles;
  486.  delay(1000);
  487. end.